"""
任务数据模型
"""
from sqlalchemy import Column, Integer, String, Text, Boolean, DateTime, JSON
from sqlalchemy.sql import func
from database import Base


class Task(Base):
    """任务模型"""
    __tablename__ = "tasks"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(255), nullable=False, comment="任务名称")
    description = Column(Text, comment="任务描述")
    source_repo_id = Column(Integer, nullable=False, comment="源代码库ID")
    target_repos = Column(JSON, nullable=False, comment="目标代码库ID列表")
    branch_mapping = Column(JSON, nullable=False, comment="分支映射配置")
    schedule_config = Column(JSON, comment="定时任务配置")
    files = Column(JSON, comment="关联文件ID列表")
    force_push = Column(Boolean, default=False, comment="是否强制推送")
    max_concurrent = Column(Integer, default=3, comment="最大并发数")
    is_active = Column(Boolean, default=True, comment="是否激活")
    created_at = Column(DateTime(timezone=True), server_default=func.now(), comment="创建时间")
    updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), comment="更新时间")